package BIO;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author fangkun
 * @create 2022-06-01-11:17
 */
public class BIOServerSocketWithThread {

    static ExecutorService executorService = Executors.newFixedThreadPool(10);

    public static void main(String[] args) {

        ServerSocket serverSocket = null;

        try {
            serverSocket = new ServerSocket(8888);
            System.out.println("启动服务：监听端口:8888");

            while (true){

                Socket socket = serverSocket.accept();
                System.out.println("客户端：" + socket.getPort());

                executorService.submit(new SocketThread(socket));
            }


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (serverSocket != null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
